package com.example.demo.controller;

import com.example.demo.entity.Inventory;
import com.example.demo.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    @GetMapping
    public List<Inventory> getAllInventory() {
        return inventoryService.list();
    }

    @GetMapping("/{id}")
    public Inventory getInventoryById(@PathVariable Integer id) {
        return inventoryService.getById(id);
    }

    @PostMapping
    public boolean createInventory(@RequestBody Inventory inventory) {
        return inventoryService.save(inventory);
    }

    @PutMapping("/{id}")
    public boolean updateInventory(@PathVariable Integer id, @RequestBody Inventory inventory) {
        inventory.setInventoryId(id); // 假设实体中有setInventoryId方法
        return inventoryService.updateById(inventory);
    }

    @DeleteMapping("/{id}")
    public boolean deleteInventory(@PathVariable Integer id) {
        return inventoryService.removeById(id);
    }
}
